package net.NingXiaRuiTai.ShortChain.config;

import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import static java.lang.Math.abs;

@Component
public class ShardingTableConfig {
    /**
     * 存储数据表位置编号
     *
     */
    private static final List<String> tableSuffixList = new ArrayList<>();
//    private static Random random = new Random();
    static {
        tableSuffixList.add("0");
        tableSuffixList.add("a");

    }
    /**
     * 随机获取后缀
     * @return
     */
    public static String getRandomTableSuffix(String code){
        return tableSuffixList.get(abs(code.hashCode())%tableSuffixList.size());
    }
}
